package com.biz.primus.model.sso.auth.vo;

import com.biz.primus.base.enums.CommonStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.Collection;

/**
 * Created by younger on 17/11/3.
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MenuGroupVO extends AbstractDescribableItem{
    private static final long serialVersionUID = 3841942588052379558L;

    private String icon;
    private Collection<MenuItemVO> menuItems;
    private MenuGroupVO parent;
    private Collection<MenuGroupVO> children = Sets.newHashSet();
    private CommonStatus status = CommonStatus.ENABLE;


    public MenuGroupVO(){

    }

    public MenuGroupVO(String id, String name, String description, String icon, CommonStatus status, Integer orderIndex) {
        super(id, name, description, orderIndex, status);
        this.icon = icon;
    }

    public void addMenuItem(MenuItemVO menuItem) {
        if (menuItems == null) {
            menuItems = Lists.newArrayList();
        }
        if (!menuItems.contains(menuItem)){
            menuItems.add(menuItem);
        }
    }

    public void addChild(MenuGroupVO childOfCurrentMenuGroup) {
        if (children == null) {
            children = Sets.newHashSet();
        }
        children.add(childOfCurrentMenuGroup);
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }


    /**
     * {@linkplain MenuGroupVO#icon}
     */
    public String getIcon() {
        return icon;
    }

    /**
     * {@linkplain MenuGroupVO#icon}
     */
    public void setIcon(String icon) {
        this.icon = icon;
    }

    /**
     * {@linkplain MenuGroupVO#menuItems}
     */
    public Collection<MenuItemVO> getMenuItems() {
        return menuItems;
    }

    /**
     * {@linkplain MenuGroupVO#menuItems}
     */
    public void setMenuItems(Collection<MenuItemVO> menuItems) {
        this.menuItems = menuItems;
    }

    /**
     * {@linkplain MenuGroupVO#children}
     */
    public Collection<MenuGroupVO> getChildren() {
        return children;
    }


    /**
     * {@linkplain MenuGroupVO#children}
     */
    public void setChildren(Collection<MenuGroupVO> children) {
        this.children = children;
    }

    /**
     * 得到父菜单
     */
    public MenuGroupVO getParent() {
        return parent;
    }

    /**
     * 设置父菜单
     */
    public void setParent(MenuGroupVO parent) {
        this.parent = parent;
    }

    /**
     * 状态
     */
    @Override
    public CommonStatus getStatus() {
        return status;
    }

    /**
     * 状态
     */
    @Override
    public void setStatus(CommonStatus status) {
        this.status = status;
    }

}
